// 云函数入口文件
const cloud = require('wx-server-sdk')
const Sequelize = require('sequelize')
const sequelize = new Sequelize('text', 'root', '', {
  host: 'localhost',
  dialect: 'mysql',
  port: 3306,
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  }
})
//创建模型对象 sequelize.define('name', {attributes}, {options})

const User = sequelize.define('singer_user', {
  openid: {
    type: Sequelize.STRING
    //要是主键的话就用prinmaryKey：true
  },
  name: {
    type: Sequelize.STRING
  },
  number: {
    type: Sequelize.STRING
  },
  password: {
    type: Sequelize.STRING
  }
})


cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
})

// 云函数入口函数
exports.main = async (event, context) => {
  await User.sync({
      alter: true
    })
    .then(res => {
      User.create({
        openid: '1',
        name: '大笨老师',
        number: 'asdc',
        password: '12345685'
      });
    }).then(finish => {
      return finish
    })

}